package com.mioto.ld.communication.websocket.resolver;


import com.mioto.ld.communication.mqtt.MqttHelper;
import com.mioto.ld.communication.websocket.model.SendCmdEnum;
import com.mioto.ld.communication.websocket.model.WsAttributeSetBody;
import com.mioto.ld.communication.websocket.model.WsRecMessage;
import com.mioto.ld.communication.websocket.util.MessageSendUtil;
import io.netty.channel.ChannelHandlerContext;


/**
 * @author mioto-qinxj
 * @date 2024/5/16
 * @desc
 */
public class WsAttributeSetResolver implements WsMessageResolver{
    @Override
    public void resolve(ChannelHandlerContext channelHandlerContext, WsRecMessage message) {
        WsAttributeSetBody attributeSetBody = (WsAttributeSetBody) message.getBody();
        if (MqttHelper.containsSn(attributeSetBody.getSn())) {
            MqttHelper.controlAttributeSet(message);
        }else {
            MessageSendUtil.send(channelHandlerContext.channel(), SendCmdEnum.DEVICE_OFFLINE);
        }
    }
}
